#include <iostream>
#include <cstring>
using namespace std;

const int N = 20; // 这里得开大一点,虽然合规的数不会超过n,但2n-2以内的数都可能参与判断
int top[N], lhs[N], rhs[N], n;
char arr[N][N];

void dfs(int cur)
{
    if(cur == n)
    {
        for(int i = 0; i < n; ++i)
                cout << arr[i] << endl;
        cout << endl;
        return;
    }
    for(int i = 0; i < n; ++i)
    {
        if(top[i] || lhs[cur + i] || rhs[cur + n - i]) continue;
        top[i] = lhs[cur + i] = rhs[cur + n - i] = 1;
        arr[cur][i] = 'Q';
        dfs(cur + 1);
        arr[cur][i] = '.';
        top[i] = lhs[cur + i] = rhs[cur + n - i] = 0;
    }
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) arr[i][j] = '.';
    dfs(0);
    
    return 0;
}